/**
 * 
 */
package com.idea.zd.sys.service;

import com.idea.zd.sys.model.Log;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.server.BaseService;

/**
 * @author y.z
 */
public class LogService extends BaseService<Log> {

	
	/**
	 * 获取分页数据
	 * @param curPage
	 * @param startDate
	 * @param endDate
	 * @param errStatus
	 * @return
	 */
	public Page<Log> getPage(int curPage,String startDate,String endDate,String errStatus){
		
		String sql = "from sys_log where 1=1";
		
		if(!StrKit.isBlank(startDate)){
			sql += " and start_time >= '"+startDate+" 00:00:00'";
		}
		
		if(!StrKit.isBlank(endDate)){
			sql += " and start_time <= '"+endDate+" 23:59:59'";
		}
		
		if(!StrKit.isBlank(errStatus)){
			String errStr = "0";
			
			if("2".equals(errStatus)){
				errStr = "-1";
			}
			sql += " and err_code = '"+errStr+"'";
			
		}
		
		return super.getPage(curPage, "select * ", sql+ " order by start_time desc");
	}
	
	/**
	 * 添加日志
	 * @param log
	 * @return
	 */
	public boolean save(Log log){
		return super.save(log);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	public boolean delete(int id){
		return super.delById(id);
	}
	
}
